package cn.bytecollege.controller;

import cn.bytecollege.entity.Room;
import cn.bytecollege.service.RoomService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RoomUpdateController",value = "/roomUpdate")
public class RoomUpdateController extends HttpServlet {
    private RoomService roomService = null;
    public RoomUpdateController(){
        roomService = new RoomService();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1接收请求参数
        String number = request.getParameter("number");
        String categoryId = request.getParameter("categoryId");
        String price = request.getParameter("price");
        String id = request.getParameter("id");

        Integer roomNumber = Integer.valueOf(number);
        Integer roomCategoryId = Integer.valueOf(categoryId);
        Double roomPrice = Double.valueOf(price);
        Integer roomId = Integer.valueOf(id);
        //2.封装数据
        Room room = new Room();
        room.setRoomNumber(roomNumber);
        room.setRoomCategoryId(roomCategoryId);
        room.setRoomPrice(roomPrice);
        room.setDeleteFlag(0);
        room.setRoomId(roomId);
        room.setRoomState(0);
        //3.调用Service方法
        roomService.update(room);
        //4.跳转页面
        response.sendRedirect(request.getContextPath() + "/roomList");

    }
}
